package com.cdsxlc.common.utils;

import com.cdsxlc.common.constant.GeneratorConstant;

import java.util.Map;

/**
 * @author zhang
 */
public class StringUtils extends org.apache.commons.lang3.StringUtils{

    public static String formatNameCamel(String source) {
        if(!source.contains(GeneratorConstant.UNDERLINE)){
            return source;
        }
        String[] arr = source.split(GeneratorConstant.UNDERLINE);
        source = arr[0].toLowerCase();
        for (int i = 1; i < arr.length; i++) {
            source += arr[i].substring(0, 1).toUpperCase() + arr[i].substring(1);
        }
        return source;
    }

    /**
     * 首字母小写
     * @param source
     * @return
     */
    public static String firstLowerCase(String source) {
        if(isBlank(source)){
            return "";
        }
        String[] arr = source.split(GeneratorConstant.UNDERLINE);
        source = "";
        for (int i = 0; i < arr.length; i++) {
            source += arr[i].substring(0, 1).toLowerCase() + arr[i].substring(1);
        }
        return source;
    }



    public static String replace(String text, Map<String, String> map) {
        if (map != null && map.size() > 0) {
            for (Map.Entry<String, String> entry : map.entrySet()) {
                text = text.replace("${" + entry.getKey() + "}", entry.getValue());
            }
        }
        return text;
    }

    public static String getClassName(String source) {
        String[] arr = source.split(GeneratorConstant.UNDERLINE);
        source = "";
        for (int i = 0; i < arr.length; i++) {
            source += arr[i].substring(0, 1).toUpperCase() + arr[i].substring(1);
        }
        return source;
    }
}
